package movEat.Definitions;

import java.util.ArrayList;
import java.util.Comparator;

public class Pair<A, B> {
    private A first;
    private B second;

    public static Comparator<Pair<String, Integer>> nameComperator = new Comparator<Pair<String,Integer>>() {
		
		@Override
		public int compare(Pair<String, Integer> a, Pair<String, Integer> b) {
			
			return a.getFirst().compareTo(b.getFirst());
				
		}
	};
	
	public static Comparator<Pair<String, Integer>> starsHighFirstComperator = new Comparator<Pair<String,Integer>>() {
		
		@Override
		public int compare(Pair<String, Integer> a, Pair<String, Integer> b) {
			
			int res = b.getSecond()-a.getSecond();
			if(res!=0)
				return res;
			else
				return a.getFirst().compareTo(b.getFirst());
				
		}
	};
	
	public Pair(A first, B second) {
        super();
        this.first = first;
        this.second = second;
    }

    public int hashCode() {
        int hashFirst = first != null ? first.hashCode() : 0;
        int hashSecond = second != null ? second.hashCode() : 0;

        return (hashFirst + hashSecond) * hashSecond + hashFirst;
    }

    public boolean equals(Object other) {
        if (other instanceof Pair) {
                Pair otherPair = (Pair) other;
                return 
                ((  this.first == otherPair.first ||
                        ( this.first != null && otherPair.first != null &&
                          this.first.equals(otherPair.first))) &&
                 (      this.second == otherPair.second ||
                        ( this.second != null && otherPair.second != null &&
                          this.second.equals(otherPair.second))) );
        }

        return false;
    }

    public String toString()
    { 
           return first + " ($" + second + ")"; 
    }

    public A getFirst() {
        return first;
    }

    public void setFirst(A first) {
        this.first = first;
    }

    public B getSecond() {
        return second;
    }

    public void setSecond(B second) {
        this.second = second;
    }

	
    public static String[] pairListToStringArray(ArrayList<Pair<String, Integer>> pairList) {
    	String[] res = new String[pairList.size()];
    	for(int i = 0; i<res.length;i++){
    		res[i]=pairList.get(i).toString();
    	}

		return res;
	}

    
    
}